package controller;

import java.util.List;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import context.AppContext;
import pojo.Customer;
import service.CustomerManager;

@RestController
@RequestMapping("/")
public class CustomerController {
	
	private CustomerManager manager;
	
	public CustomerController() {
		///MVC容器 去IOC容器 中拿
		manager = AppContext.getInstance().getBean(CustomerManager.class);
	}
	
	@RequestMapping(value="/addCustomer", method=RequestMethod.POST ,consumes="application/json")
	public Customer addCustomer(@RequestBody Customer c){
		return manager.addCustomer(c);
	}
	@RequestMapping(value="/updateCustomer", method=RequestMethod.POST ,consumes="application/json")
	public Customer updateCustomer(@RequestBody Customer c){
		return manager.updateCustomer(c);
	}
	@RequestMapping(value="/deleteCustomer", method=RequestMethod.DELETE)
	public String deleteCustomer(String id){
		System.out.println("要刪除的id是： "+ id);
		return manager.deleteCustomer(id);
	}
	
	@RequestMapping(value="/findAllCustomers", method=RequestMethod.GET)
	public List<Customer> findAllCustomers(){
		return manager.findAllCustomers();
	}
}
